package cn.wolfcode.trip.base.service.impl;


import cn.wolfcode.trip.base.domain.Click;
import cn.wolfcode.trip.base.mapper.ClickMapper;
import cn.wolfcode.trip.base.query.ClickQueryObject;
import cn.wolfcode.trip.base.query.CollectionceQueryObject;
import cn.wolfcode.trip.base.service.IClickService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ClickServiceImpl implements IClickService {

    @Autowired
    private ClickMapper clickMapper;


    @Override
    public boolean selectId(CollectionceQueryObject qo) {
        return clickMapper.selectId(qo)>0;
    }

    @Override
    public void save(CollectionceQueryObject qo) {
        qo.setState(false);
        if (qo.getTravelId()!=null){
            clickMapper.save(qo);
        }else if (qo.getStrategyId() !=null){
            clickMapper.save1(qo);
        }else {
            clickMapper.save2(qo);
        }

    }

    @Override
    public void delete(CollectionceQueryObject qo) {
        if (qo.getTravelId() != null){
            clickMapper.delete(qo);
        }else if (qo.getStrategyId() != null){
            clickMapper.delete1(qo);
        }else {
            clickMapper.delete2(qo);
        }
    }

    @Override
    public PageInfo query(ClickQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Click> clicks = clickMapper.query(qo);
        return new PageInfo(clicks);
    }

    @Override
    public Integer getNoReadCount(Long userId) {
        return clickMapper.getNoReadCount(userId);
    }

    @Override
    public void setRead(Long userId) {
        clickMapper.setRead(userId);
    }
    @Override
    public Integer selsectId(Long strategyId) {
        return clickMapper.selsectId(strategyId);
    }




}
